/* vuex模块化-user模块 */
// import { login } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/storage'
import { getUserInfo } from '@/api/user'
export default {
  namespaced: true,
  state: {
    token: getToken(),
    // 获取用户信息
    userInfo: {},
    channelList: []
  },
  mutations: {
    setToken (state, token) {
      // console.log(3, token)
      state.token = token
      // 保存token到localStorage中
      setToken(token)
    },
    removeToken (state) {
      state.token = {}
      removeToken()
    },
    setUserInfo (state, payload) {
      state.userInfo = payload
    }
  },
  actions: {
    async getUserInfo (context) {
      // 发送ajax请求
      const res = await getUserInfo()
      // this.userInfo = res.data
      context.commit('setUserInfo', res.data)
    }
  }
}

